.<template>
	<view class="register">

		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput v-model="passData" type="password" maxlength="11" placeholder="密码:" isShowPass></wInput>
				<wInput v-model="confirmPwd" type="password" maxlength="11" placeholder="确定密码:" isShowPass></wInput>
			</view>
			<wButton text="确定" :rotate="isRotate" @click.native="startReg()"></wButton>

		</view>
	</view>
</template>

<script>
	var _this;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button

	export default {
		data() {
			return {
				//logo图片 base64
				logoImage: '',
				phoneData: '', // 用户/电话
				passData: '', //密码
				confirmPwd: '', //再一次确定密码
				showAgree: true, //协议是否选择
				isRotate: false, //是否加载旋转
			}
		},
		components: {
			wInput,
			wButton,
		},
		mounted() {
			_this = this;
		},
		methods: {

			restPassword() {
				var _this = this;
				var id = uni.getStorageSync('user_info').id
				uni.request({
					url: _this.api + "/user/resetPassword", //登陆
					method: "POST",
					data: {
						id: id,
						password: this.passData
					},
					header: {
						"content-type": "application/x-www-form-urlencoded"
					},
					success: (res) => {

						if (res.data.code == 200) {
							console.log(res)
							uni.showToast({
								title: "修改成功！",
								icon: 'none',
								duration: 1000
							})
						}


					},
					fail: (err) => {
						uni.showToast({
							title: "修改失败！",
							icon: 'none',
							duration: 1000
						})
					}
				})
			},

			isShowAgree() {
				//是否选择协议
				_this.showAgree = !_this.showAgree;
			},
			startReg() {
				//注册
				if (this.isRotate) {
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.passData != this.confirmPwd) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '两次密码不一致'
					});
					return false;
				}


				this.restPassword()

				_this.isRotate = true
				setTimeout(function() {
					_this.isRotate = false
				}, 3000)
			}
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("../login/css/main.css");
</style>
